package com.example.module_properties.adapter

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.module_properties.R
import com.yuwei.http.entity.PropertiesEntityItem
import com.yuwei.http.entity.PropertiesItem

class ProrperAdapter:BaseQuickAdapter<PropertiesItem,BaseViewHolder>(R.layout.prop_item) {
    private val properItemAdapter = ProperItemAdapter()
    private var position = -1
    fun setPosition(position: Int){
        this.position = position
    }
    private var list = mutableListOf<PropertiesEntityItem>()
    fun setList(listItem:MutableList<PropertiesEntityItem>){
        this.list = listItem
    }
    override fun convert(holder: BaseViewHolder, item: PropertiesItem) {

        properItemAdapter.notifyDataSetChanged()
        holder.setText(R.id.prop_item_tt1, "${ item.regionId }栋")
        holder.setText(R.id.prop_item_pf,"${item.area}m²")
        val rv = holder.getView<RecyclerView>(R.id.prop_rv1)
        if(position == holder.adapterPosition){

            rv.visibility = View.VISIBLE
        }else{
            rv.visibility = View.GONE
        }

        rv.adapter = properItemAdapter
        rv.layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)
        properItemAdapter.data.clear()
        properItemAdapter.data.addAll(list)
    }
}